$(document).ready(function(){
getSay();		
	//用户名
	$("#username").blur(function(){
		var value = $(this).val();
		$.get('/user/index/check/type/username/value/'+value,function(rs){
			$("#username_info").html(rs);
		})
	}).focusout(function(){
		$(this).removeClass('click');
	}).focus(function(){		
		$(this).addClass('click');
	})
	
	//邮箱
	$("#email").blur(function(){
		var value = $(this).val();
		$.get('/user/index/check/type/email/value/'+value,function(rs){
			$("#email_info").html(rs);
		})
	}).focusout(function(){
		$(this).removeClass('click');
	}).focus(function(){		
		$(this).addClass('click');
	})
	
	//密码
	$("#password").blur(function(){
		var value = $(this).val();
		if(value.length<6){
			$("#password_info").html('<span class="info">密码必须大于6位</span>');
		}else{
			$("#password_info").html('<span  style="float:left;margin:10px 0;"><img src="/source/images/ok.gif"></span>');
			//检查重复密码
			var password = $('#password1').val();
			if(value!=password){
				$("#password1_info").html('<span class="info">两次密码不一致</span>');
			}
		}
	}).focusout(function(){
		$(this).removeClass('click');
	}).focus(function(){		
		$(this).addClass('click');
	})	
	
	//重复密码
	$("#password1").blur(function(){
		var value = $(this).val();
		var password = $('#password').val();
		if(value!=password || value.length<6){
			$("#password1_info").html('<span class="info">两次密码不一致</span>');
		}else{
			$("#password1_info").html('<span  style="float:left;margin:10px 0;"><img src="/source/images/ok.gif"></span>');
		}
	}).focusout(function(){
		$(this).removeClass('click');
	}).focus(function(){		
		$(this).addClass('click');
	})
	
	//发表心情
	$('#say_submit').click(function(){
		var content = $('#say').val();
		$.post('/user/say/add',{'content':content,'type':'心情'},function(rs){
			if($.trim(rs)==1){
				$('#say').attr('value','');
				getSay();
			}else{
				alert('false');
			}
		});
	});
	
	//个人中心菜单
	$('.menu li').click(function(){
		$.each($('.menu li'),function(i,val){
			$(this).removeClass('selected');
		})
		$(this).addClass('selected');
	})

	

})

function updateavatar() {
	window.location.reload();
}

function checkLogin(){
	var username = $("#username").val();
	var password = $("#password").val();
	if(username.length<1){
		alert('请输入正确的用户名');
		return false;
	}else if(password.length<2){
		alert('请输入正确的密码');
		return false;
	}
	return true;
}

function checkRegister(){
	var user = $('#username_info').html().toLowerCase();
	var email = $('#email_info').html().toLowerCase();
	var password = $('#password_info').html().toLowerCase();
	var password1 = $('#password1_info').html().toLowerCase();

	if(user.indexOf('ok.gif')<0 || email.indexOf('ok.gif')<0 || password.indexOf('ok.gif')<0 || password1.indexOf('ok.gif')<0 ){
		alert('请检查各项填写是否正确');
		return false;	
	}else{
		return true;	
	}
}

function SetCwinHeight(){
	var iframeid=document.getElementById("iframeid"); //iframe id
	if (document.getElementById){
		if (iframeid && !window.opera){
			if (iframeid.contentDocument && iframeid.contentDocument.body.offsetHeight){
				iframeid.height = iframeid.contentDocument.body.offsetHeight;
			}else if(iframeid.Document && iframeid.Document.body.scrollHeight){
				iframeid.height = iframeid.Document.body.scrollHeight;
			}
		}
	}
}

//获取用户说的内容
function getSay(type,user,order){
 
	$('#say_content').html();
	$.getJSON('/user/say/get',{'type':type,'uid':user,'order':order},function(data){
		var str = '';
		$.each(data,function(i,item){
			str += '<table border="0" class="profile_info_item">'+
				'<tr>'+
					'<td class="avatar">'+data[i].avatar+'</td>'+
					'<td class="info">'+data[i].info+'</td>'+
				'</tr>'+
				'<tr>'+
					'<td colspan="2" align="right">'+data[i].time+'</td>'+
				'</tr>'+
			'</table>';
		})
		$('#say_content').html(str);
	})	
}
